
import { WeaBrowser,WeaRadioGroup} from 'ecCom'
import { Button,message} from 'antd'
import isEqual from 'lodash/isEqual';
import * as mobx from 'mobx';
/**
 * 高级查询
 * props
 * advanceSearchPara ： 高级查询数据
 */
export default class Main extends React.Component{
	constructor(props) {
		super(props);
	}
	
	shouldComponentUpdate(nextProps) {
		const _c = !isEqual(mobx.toJS(this.props.advanceSearchData), mobx.toJS(nextProps.advanceSearchData));
        return _c || this.props.tabKey !== nextProps.tabKey;
    }

	render(){
		const config = this.getAdvanceSearchConfig();
		return (
			<div className="advance-search-container">
				<WeaRadioGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaRadioGroup@w4yyxb`} config={config} onChange={this.doConditonChange.bind(this)}/>
			</div>
		)
	}
	
	//初始化配置数据
	getAdvanceSearchConfig(){
		const {tabKey = 1,advanceSearchData,advanceSearchPara = {}} = this.props;
		const {orgtype = 3} =  advanceSearchPara;
		//更新label
		const {config =[]} = advanceSearchData;
		const ___config  = mobx.toJS(config);
		
		if(___config.length > 0){
			const orgItem = ___config[0];
			const __options = orgItem.options.filter(o=>{
				if(tabKey == 2) return o.key < 4;
				if(tabKey == 3) return o.key < 3;
				return true;
			});
			
			__options.map(o=>{
				if(orgtype == o.key) {
					o.selected = true;
				} else {
					o.selected = false;
				}
			});
			orgItem.options = __options;
			const {otherParams = {}} = orgItem;
			if(tabKey > 1) {
				orgItem.label = otherParams['tablabel'+tabKey];
			}
			___config[0] = orgItem;
		}
		return ___config;
	}
	
	doConditonChange(data = {}){
		const {updateAdvanceSearchPara} = this.props;
		updateAdvanceSearchPara && updateAdvanceSearchPara(data);
	}
}